# -*- coding: iso-8859-1 -*-
# file Generic6DofJoint.py
# author Rocco Martino
#
############################################################################
#    Copyright (C) 2015 by Rocco Martino                                   #
#    martinorocco@gmail.com                                                #
#                                                                          #
#    This program is free software; you can redistribute it and/or modify  #
#    it under the terms of the GNU Lesser General Public License as        #
#    published by the Free Software Foundation; either version 2.1 of the  #
#    License, or (at your option) any later version.                       #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU Lesser General Public License for more details.                   #
#                                                                          #
#    You should have received a copy of the GNU Lesser General Public      #
#    License along with this program; if not, write to the                 #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

############################################################################
from . import Joint
############################################################################




############################################################################
# ........................................................................ #
# ........................................................................ #
############################################################################




############################################################################
# ........................................................................ #
class Generic6DofJoint(Joint.Joint):





############################################################################
############################################################################









############################################################################
    def __init__(self, obj, data, constraint):
        super(Generic6DofJoint, self).__init__(obj, data, constraint)

        self.ClassName = "osgODE::Generic6DofJoint"

        self.UseLocalValues = True
############################################################################




############################################################################
    def writeData(self, writer):
        super(Generic6DofJoint, self).writeData(writer)



        erp = self.Data.ERP * 60.0 / self.Data.CurrentScene.game_settings.fps
        cfm = self.Data.CFM * 60.0 / self.Data.CurrentScene.game_settings.fps
        stop_erp = self.Data.StopERP * 60.0 / self.Data.CurrentScene.game_settings.fps
        stop_cfm = self.Data.StopCFM * 60.0 / self.Data.CurrentScene.game_settings.fps





        obj = self.BlenderObject

        limits = [ obj.use_limit_x, obj.use_limit_y, obj.use_limit_z ]

        lo_hi = ( (obj.limit_min_x, obj.limit_max_x), (obj.limit_min_y, obj.limit_max_y), (obj.limit_min_z, obj.limit_max_z) )



        limits += [ obj.use_angular_limit_x, obj.use_angular_limit_y, obj.use_angular_limit_z ]

        lo_hi += ( (obj.limit_angle_min_x, obj.limit_angle_max_x), (obj.limit_angle_min_y, obj.limit_angle_max_y), (obj.limit_angle_min_z, obj.limit_angle_max_z) )




        for i in range( len(limits) ):

            if limits[i]:
                writer.writeLine( "dParamLoStop%d %f" %( i+1, lo_hi[i][0] ) )
                writer.writeLine( "dParamHiStop%d %f" %( i+1, lo_hi[i][1] ) )




            writer.writeLine("dParamCFM%d %f" %(i+1, cfm))

            writer.writeLine("dParamStopERP%d %f" %(i+1, stop_erp)) ;
            writer.writeLine("dParamStopCFM%d %f" %(i+1, stop_cfm)) ;

            writer.writeLine("dParamERP%d %f" %(i+1, erp))
############################################################################




# ........................................................................ #
############################################################################
